#!/usr/bin/python2.6
import salt.grains.core
import os
import MySQLdb
import commands
hostname=salt.grains.core.hostname()['fqdn']
hostip=salt.grains.core.ip4()['ipv4'][1]
cpuinfo=salt.grains.core.os_data()['cpu_model']
meminfo=salt.grains.core.os_data()['mem_total']
saltversion=salt.grains.core.saltversion()['saltversion']
pythonversion=commands.getoutput('python -V')
os=salt.grains.core.os_data()['osfullname'] + salt.grains.core.os_data()['osrelease']
kernelrelease=salt.grains.core.os_data()['kernelrelease']

conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='123456',db='host',port=3306)
cursor=conn.cursor()
cursor.execute('INSERT INTO info VALUES (%s,%s,%s,%s,%s,%s,%s,%s)' % ('"'+str(hostname)+'"','"'+str(hostip)+'"','"'+str(cpuinfo)+'"','"'+str(meminfo)+'"','"'+str(saltversion)+'"','"'+str(pythonversion)+'"','"'+str(os)+'"','"'+str(kernelrelease)+'"'))
conn.commit()
cursor.close()
conn.close()
print hostname,hostip,cpuinfo,meminfo,saltversion,pythonversion,os,kernelrelease
